﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Data;

namespace OtherDevice
{
    [Description("诚峰Plasma")]

    public class Plasma_诚峰 : Plasma_Base
    {
        public Plasma_诚峰(string name) : base(name)
        {
            controlFrom = new Form_Plasma();
        }

        public override bool OpenPlasma()
        {
            return true;
        }

        public override bool ClosePlasma()
        {
            return true;
        }

        public override bool Fucntion_PlasmaOK()
        {
            return true;
        }

        public override bool Function_SetPlasma功率(int nValue)
        {
            return true;
        }

        public override bool Fucntion_GetPlasma功率(ref int n_Value)
        {
            try
            {
                string str_SendMsg = "01 03 00 02 00 02 65 CB";
                byte[] array = HexStrToArrayByte(str_SendMsg);
                byte[] result = null;
                if (!SendAndReciveData(array, ref result, 3000))
                {
                    return false;
                }
                string Str_03 = Convert.ToString(result[3], 16);
                string Str_04 = Convert.ToString(result[4], 16);
                string value2 = Str_03 + Str_04;
                n_Value = Convert.ToInt32(value2, 16);
                return true;
            }
            catch (Exception)
            {
                return true;
            }
        }

        public override bool Function_GetPlasma气压(ref double d_Value)
        {
            return true;
        }

        public static byte[] HexStrToArrayByte(string str)
        {
            try
            {
                str = str.Replace(" ", "");
                byte[] array = new byte[str.Length / 2];
                for (int i = 0; i < str.Length; i += 2)
                {
                    array[i / 2] = Convert.ToByte(str.Substring(i, 2), 16);
                }

                return array;
            }
            catch (Exception)
            {
                //UIMessageBox.ShowError(ex.Message + "\r\n请确保字符串是有效的十六进制字符串");
                return new byte[0];
            }
        }
    }
}
